/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CustomerHomeViewPanel.java
 *
 * Created on Apr 29, 2010, 6:10:14 PM
 */

package ticketmaster.presentation.customer;

import javax.swing.JToolBar;
import ticketmaster.dao.DAOFactory;
import ticketmaster.dataobject.PremiumCustomer;
import ticketmaster.presentation.customer.purchase.SearchView;

/**
 *
 * @author Wei Liu
 */
public class CustomerHomeViewPanel extends CustomerBasePanel {

    /** Creates new form CustomerHomeViewPanel */
    public CustomerHomeViewPanel() {
        initComponents();
        initMainPanel();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar(null, JToolBar.VERTICAL);
        btnBuy = new javax.swing.JButton();
        btnTickets = new javax.swing.JButton();
        btnAccount = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        pnlMain = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ticketmaster.TicketMasterApp.class).getContext().getResourceMap(CustomerHomeViewPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setRollover(true);
        jToolBar1.setFloatable(false);
        jToolBar1.setFocusable(false);
        jToolBar1.setRequestFocusEnabled(false);
        jToolBar1.setName("jToolBar1"); // NOI18N

        btnBuy.setBackground(resourceMap.getColor("btnBuy.background")); // NOI18N
        btnBuy.setIcon(resourceMap.getIcon("btnBuy.icon")); // NOI18N
        btnBuy.setText(resourceMap.getString("btnBuy.text")); // NOI18N
        btnBuy.setFocusable(false);
        btnBuy.setName("btnBuy"); // NOI18N
        btnBuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuyActionPerformed(evt);
            }
        });
        jToolBar1.add(btnBuy);

        btnTickets.setBackground(resourceMap.getColor("btnTickets.background")); // NOI18N
        btnTickets.setIcon(resourceMap.getIcon("btnTickets.icon")); // NOI18N
        btnTickets.setText(resourceMap.getString("btnTickets.text")); // NOI18N
        btnTickets.setFocusable(false);
        btnTickets.setName("btnTickets"); // NOI18N
        btnTickets.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTicketsActionPerformed(evt);
            }
        });
        jToolBar1.add(btnTickets);

        btnAccount.setBackground(resourceMap.getColor("btnAccount.background")); // NOI18N
        btnAccount.setIcon(resourceMap.getIcon("btnAccount.icon")); // NOI18N
        btnAccount.setText(resourceMap.getString("btnAccount.text")); // NOI18N
        btnAccount.setFocusable(false);
        btnAccount.setName("btnAccount"); // NOI18N
        btnAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAccountActionPerformed(evt);
            }
        });
        jToolBar1.add(btnAccount);

        btnEdit.setBackground(resourceMap.getColor("btnEdit.background")); // NOI18N
        btnEdit.setIcon(resourceMap.getIcon("btnEdit.icon")); // NOI18N
        btnEdit.setText(resourceMap.getString("btnEdit.text")); // NOI18N
        btnEdit.setFocusable(false);
        btnEdit.setName("btnEdit"); // NOI18N
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });
        jToolBar1.add(btnEdit);

        add(jToolBar1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 1, 150, 610));

        pnlMain.setBackground(resourceMap.getColor("pnlMain.background")); // NOI18N
        pnlMain.setName("pnlMain"); // NOI18N

        javax.swing.GroupLayout pnlMainLayout = new javax.swing.GroupLayout(pnlMain);
        pnlMain.setLayout(pnlMainLayout);
        pnlMainLayout.setHorizontalGroup(
            pnlMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 860, Short.MAX_VALUE)
        );
        pnlMainLayout.setVerticalGroup(
            pnlMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 620, Short.MAX_VALUE)
        );

        add(pnlMain, new org.netbeans.lib.awtextra.AbsoluteConstraints(174, -4, 860, 620));

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator1.setName("jSeparator1"); // NOI18N
        add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 0, 10, 620));
    }// </editor-fold>//GEN-END:initComponents

    private void btnBuyActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnBuyActionPerformed
    {//GEN-HEADEREND:event_btnBuyActionPerformed
        SearchView sv = new SearchView();
        this.pnlMain.removeAll();
        this.pnlMain.add(sv);
        this.pnlMain.validate();
        this.pnlMain.repaint();
        sv.setPnlParent(pnlMain);
    }//GEN-LAST:event_btnBuyActionPerformed

    private void btnTicketsActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnTicketsActionPerformed
    {//GEN-HEADEREND:event_btnTicketsActionPerformed
        CustomerTicketsView ctv = new CustomerTicketsView();
        this.pnlMain.removeAll();
        this.pnlMain.add(ctv);
        this.pnlMain.validate();
        this.pnlMain.repaint();
        ctv.setPnlParent(pnlMain);
    }//GEN-LAST:event_btnTicketsActionPerformed

    private void btnAccountActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnAccountActionPerformed
    {//GEN-HEADEREND:event_btnAccountActionPerformed
        CustomerAccountView cav;
        PremiumCustomerPanel pcv;
        int userID = getUser().getUserID();
        PremiumCustomer pc = new PremiumCustomer();
        pc.setCustomerID(userID);
        this.pnlMain.removeAll();
        if(DAOFactory.getInstance().getPremiumCustomerDAO().findPremiumCustomer(pc) != null)
        {
            pcv = new PremiumCustomerPanel();
            this.pnlMain.add(pcv);
            pcv.setPnlParent(pnlMain);
        }
        else
        {
            cav = new CustomerAccountView();
            this.pnlMain.add(cav);
            cav.setPnlParent(pnlMain);
        }
        this.pnlMain.validate();
        this.pnlMain.repaint();
    }//GEN-LAST:event_btnAccountActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnEditActionPerformed
    {//GEN-HEADEREND:event_btnEditActionPerformed
        CustomerProfileView cp = new CustomerProfileView();
        this.pnlMain.removeAll();
        this.pnlMain.add(cp);
        this.pnlMain.validate();
        this.pnlMain.repaint();
        cp.setPnlParent(pnlMain);
    }//GEN-LAST:event_btnEditActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAccount;
    private javax.swing.JButton btnBuy;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnTickets;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JPanel pnlMain;
    // End of variables declaration//GEN-END:variables

    private void initMainPanel()
    {
        WelcomeView wv = new WelcomeView();
        this.pnlMain.removeAll();
        this.pnlMain.add(wv);
        this.pnlMain.validate();
        this.pnlMain.repaint();
        wv.setPnlParent(pnlMain);
    }

}
